/**
 * 
 */
package com.gs.gms.model.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author Sabuj Das | sabuj.das@gmail.com
 *
 */
@Entity
@Table(name="gms_message")
public class Message {

	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="MESSAGE_ID", unique=true, nullable=false)
	private long messageId;
	
	@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="CONNECTION_ID", nullable=false)
    private UserConnection connection;
	
	@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="INCOMING_MESSAGE_ID")
    private Message recievedMessage;
	
	@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="SOURCE_USER_ID", nullable=false)
    private User sourceUser;
	
	@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="TARGET_USER_ID", nullable=false)
    private User targetUser;
	
	@Column(name="MESSAGE_BODY", nullable=false, length=500)
    private String messageBody;
	
	@Temporal(TemporalType.TIMESTAMP)
    @Column(name="SENT_AT", nullable=false, length=19)
    private Date sentAt;
	
	@Temporal(TemporalType.TIMESTAMP)
    @Column(name="RECEIVED_AT", length=19)
    private Date receivedAt;
	
	@OneToMany(fetch=FetchType.LAZY, mappedBy="recievedMessage")
	private Set<Message> replyMessages = new HashSet<>(0);

	public long getMessageId() {
		return messageId;
	}

	public void setMessageId(long messageId) {
		this.messageId = messageId;
	}

	public UserConnection getConnection() {
		return connection;
	}

	public void setConnection(UserConnection connection) {
		this.connection = connection;
	}

	public Message getRecievedMessage() {
		return recievedMessage;
	}

	public void setRecievedMessage(Message recievedMessage) {
		this.recievedMessage = recievedMessage;
	}

	public User getSourceUser() {
		return sourceUser;
	}

	public void setSourceUser(User sourceUser) {
		this.sourceUser = sourceUser;
	}

	public User getTargetUser() {
		return targetUser;
	}

	public void setTargetUser(User targetUser) {
		this.targetUser = targetUser;
	}

	public String getMessageBody() {
		return messageBody;
	}

	public void setMessageBody(String messageBody) {
		this.messageBody = messageBody;
	}

	public Date getSentAt() {
		return sentAt;
	}

	public void setSentAt(Date sentAt) {
		this.sentAt = sentAt;
	}

	public Date getReceivedAt() {
		return receivedAt;
	}

	public void setReceivedAt(Date receivedAt) {
		this.receivedAt = receivedAt;
	}

	public Set<Message> getReplyMessages() {
		return replyMessages;
	}

	public void setReplyMessages(Set<Message> replyMessages) {
		this.replyMessages = replyMessages;
	}
	
	
}
